﻿

using System.Collections.Generic;

using hq;
using hcache;
using hdal;

namespace htaskCommon {
     public abstract class AbsClearCarrierTask :ZtTask {
        public AbsClearCarrierTask(){
           time=3000;
        }
        protected IWCSServer wcsServer = WMSDalFactray.getDal<IWCSServer>();
   
       
        protected abstract Signal getCarrierSignalStatus(int path);
        protected abstract void ClearTask(PlcCarrierPoint point);
        public override void excute()
        {
          
            Dictionary<int, PlcCarrierPoint> carrierPoint = StatusCache.carrierPoint;
            foreach (var it in carrierPoint)
            {
                if (it.Value.p == 0)
                {
                    continue;
                }
                Signal carrierSignal = getCarrierSignalStatus(it.Value.p);
                if( it.Value.p == 6 ) {
                    it.Value.p = 6;
                }
                if( carrierSignal == null ) {
                    continue;
                }
                int taskNO = carrierSignal.no;
                if (taskNO == 0)
                {
                    continue;
                }
                if( !carrierSignal.isArrived() ) {
                    continue;
                }
                TaskCarrier taskCarrier = TaskCacheDB.getTaskByTaskNo<TaskCarrier>(taskNO);
               
                 if (taskCarrier == null)
                {
                    ClearTask(it.Value);
                    fileAll("托盘号为 " + taskNO + "的出入库任务不存在！ ");
                    continue;
                }
                int path = it.Value.p;
                if( taskCarrier.des != path ) {
                    continue;
                }
                 if (taskCarrier.status != 9) {
                    continue;
                }
                TaskCrane taskCrane = TaskCacheDB.getNextTaskByTaskNo<TaskCarrier,TaskCrane>(path,taskCarrier.taskNo);
                if( taskCrane != null ) {
                    if( taskCrane.status > 4 ) {
                        ClearTask(it.Value);
                    }
                 }else {
                    ClearTask(it.Value);
                 }
            }
         }
 
       
    }
}
